using System;
using System.ComponentModel;
using System.Drawing;
using System.Timers;
using System.Windows.Forms;
using ICP_MS.Plugin.Experiment.Properties;

namespace ICP_MS.Plugin.Experiment;

public class FormUptake : Form
{
	private ExperimentDatas experiment = null;

	private System.Timers.Timer timer = new System.Timers.Timer();

	private IContainer components = null;

	private Label label1;

	private Label lblSample;

	private Label label2;

	private Button btnOK;

	private Button btnCancel;

	private CheckBox checkBox1;

	private CheckBox checkBox2;

	public string Samplename { get; set; }

	public FormUptake()
	{
		InitializeComponent();
	}

	public void SetParams(ExperimentDatas experiment)
	{
		this.experiment = experiment;
	}

	private void FormUptake_Load(object sender, EventArgs e)
	{
		lblSample.Text = Samplename;
		Text = Samplename;
		Win32API.SetTopMost((Control)this);
		ApplyResources();
		if (experiment.AutosampleTable.autoSample)
		{
			base.DialogResult = DialogResult.OK;
		}
		checkBox1.Checked = Settings.Default.autoExperiment;
		if (checkBox1.Checked)
		{
			timer.Interval = 10000.0;
			timer.Elapsed += Timer_Elapsed;
			timer.Start();
		}
		Focus();
	}

	private void Timer_Elapsed(object sender, ElapsedEventArgs e)
	{
		timer.Stop();
		Invoke((MethodInvoker)delegate
		{
			base.DialogResult = DialogResult.OK;
		});
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("FormUptake.Title.Text");
		label1.Text = Lang.Txt("FormUptake.Uptake.Text");
		label2.Text = Lang.Txt("FormUptake.ConfirmSample.Text");
		btnCancel.Text = Lang.Txt("FormUptake.Button.Cancel.Text");
		btnOK.Text = Lang.Txt("FormUptake.Button.Ok.Text");
		checkBox1.Text = Lang.Txt("AddFormUptake.Text");
	}

	private void btnOK_Click(object sender, EventArgs e)
	{
		base.DialogResult = DialogResult.OK;
	}

	private void FormUptake_FormClosing(object sender, FormClosingEventArgs e)
	{
	}

	private void btnCancel_Click(object sender, EventArgs e)
	{
		base.DialogResult = DialogResult.Cancel;
	}

	private void checkBox1_CheckedChanged(object sender, EventArgs e)
	{
		Settings.Default.autoExperiment = checkBox1.Checked;
		if (!checkBox1.Checked)
		{
			timer.Stop();
		}
	}

	private void checkBox2_CheckedChanged(object sender, EventArgs e)
	{
		if (checkBox1.Checked)
		{
			checkBox2.Enabled = true;
		}
		else
		{
			checkBox2.Enabled = false;
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.label1 = new System.Windows.Forms.Label();
		this.lblSample = new System.Windows.Forms.Label();
		this.label2 = new System.Windows.Forms.Label();
		this.btnOK = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		this.checkBox1 = new System.Windows.Forms.CheckBox();
		this.checkBox2 = new System.Windows.Forms.CheckBox();
		base.SuspendLayout();
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(16, 24);
		this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(119, 20);
		this.label1.TabIndex = 0;
		this.label1.Text = "提升样品...";
		this.lblSample.AutoSize = true;
		this.lblSample.Font = new System.Drawing.Font("宋体", 12f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
		this.lblSample.ForeColor = System.Drawing.Color.Blue;
		this.lblSample.Location = new System.Drawing.Point(120, 24);
		this.lblSample.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.lblSample.Name = "lblSample";
		this.lblSample.Size = new System.Drawing.Size(42, 20);
		this.lblSample.TabIndex = 1;
		this.lblSample.Text = "...";
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(39, 65);
		this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(269, 20);
		this.label2.TabIndex = 2;
		this.label2.Text = "请确认样品已进入，按确认键";
		this.btnOK.Location = new System.Drawing.Point(42, 102);
		this.btnOK.Margin = new System.Windows.Forms.Padding(4);
		this.btnOK.Name = "btnOK";
		this.btnOK.Size = new System.Drawing.Size(100, 31);
		this.btnOK.TabIndex = 1;
		this.btnOK.Text = "确认";
		this.btnOK.UseVisualStyleBackColor = true;
		this.btnOK.Click += new System.EventHandler(btnOK_Click);
		this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
		this.btnCancel.Location = new System.Drawing.Point(150, 102);
		this.btnCancel.Margin = new System.Windows.Forms.Padding(4);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(100, 31);
		this.btnCancel.TabIndex = 3;
		this.btnCancel.Text = "取消";
		this.btnCancel.UseVisualStyleBackColor = true;
		this.btnCancel.Click += new System.EventHandler(btnCancel_Click);
		this.checkBox1.AutoSize = true;
		this.checkBox1.Location = new System.Drawing.Point(284, 139);
		this.checkBox1.Name = "checkBox1";
		this.checkBox1.Size = new System.Drawing.Size(111, 24);
		this.checkBox1.TabIndex = 4;
		this.checkBox1.Text = "自动测试";
		this.checkBox1.UseVisualStyleBackColor = true;
		this.checkBox1.CheckedChanged += new System.EventHandler(checkBox1_CheckedChanged);
		this.checkBox2.AutoSize = true;
		this.checkBox2.Enabled = false;
		this.checkBox2.Location = new System.Drawing.Point(150, 139);
		this.checkBox2.Name = "checkBox2";
		this.checkBox2.Size = new System.Drawing.Size(111, 24);
		this.checkBox2.TabIndex = 5;
		this.checkBox2.Text = "自动熄火";
		this.checkBox2.UseVisualStyleBackColor = true;
		this.checkBox2.Visible = false;
		this.checkBox2.CheckedChanged += new System.EventHandler(checkBox2_CheckedChanged);
		base.AcceptButton = this.btnOK;
		base.AutoScaleDimensions = new System.Drawing.SizeF(10f, 20f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.CancelButton = this.btnCancel;
		base.ClientSize = new System.Drawing.Size(428, 175);
		base.Controls.Add(this.checkBox2);
		base.Controls.Add(this.checkBox1);
		base.Controls.Add(this.btnCancel);
		base.Controls.Add(this.btnOK);
		base.Controls.Add(this.label2);
		base.Controls.Add(this.lblSample);
		base.Controls.Add(this.label1);
		this.Font = new System.Drawing.Font("宋体", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		base.Margin = new System.Windows.Forms.Padding(4);
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "FormUptake";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "提升样品";
		base.TopMost = true;
		base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormUptake_FormClosing);
		base.Load += new System.EventHandler(FormUptake_Load);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
